package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.BussinessItemVo;
import com.ruoyi.base.domain.PublicToolsVo;
import com.ruoyi.base.service.PublicToolsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/tools")
public class PublicToolsController extends BaseController {

    @Autowired
    private PublicToolsService publicToolsService;

    /**
     * 获取监测因子信息
     */
    @GetMapping("/bussinessItemData")
    public AjaxResult bussinessItemData(BussinessItemVo vo){

        List<Map<String,Object>> list=publicToolsService.bussinessItemData(vo);
        return AjaxResult.success(list);
    }


    /**
     *区划树监测断面
     */
    @GetMapping("/segmentRegionTree")
    public AjaxResult segmentRegionTree(PublicToolsVo vo){

        if (StringUtils.isNotEmpty(vo.getControlLevel())) {
            String[] arr = vo.getControlLevel().split(",");
            List<String>  controlLevels = Arrays.asList(arr);
            vo.setControlLevels(controlLevels);
        }

        if (StringUtils.isNotEmpty(vo.getAssessTypeCode())) {
            String[] arr = vo.getAssessTypeCode().split(",");
            List<String>   assessTypeCodes = Arrays.asList(arr);
            vo.setAssessTypeCodes(assessTypeCodes);
        }
        List<Map<String,Object>> List = publicToolsService.segmentRegionTree(vo);
        return AjaxResult.success(List);
    }
    /**
     * 河流树监测断面
     */
    @GetMapping("/segmentRiverTree")
    public AjaxResult segmentRiverTree(PublicToolsVo vo){
        if (StringUtils.isNotEmpty(vo.getControlLevel())) {
            String[] arr = vo.getControlLevel().split(",");
            List<String>  controlLevels = Arrays.asList(arr);
            vo.setControlLevels(controlLevels);
        }

        if (StringUtils.isNotEmpty(vo.getAssessTypeCode())) {
            String[] arr = vo.getAssessTypeCode().split(",");
            List<String>   assessTypeCodes = Arrays.asList(arr);
            vo.setAssessTypeCodes(assessTypeCodes);
        }
        List<Map<String,Object>> list = new ArrayList<>();
        //outCountry传值1的时候，增加where条件判断，and ifnull(IsCountryAuto,0)!=1。默认参数值为0，返回全部数据，不加这个条件
        if ("IsManual".equals(vo.getSegmentType())) {
            list = publicToolsService.RiverSectionTree(vo);
        } else if ("IsAuto".equals(vo.getSegmentType())) {

            list = publicToolsService.RiverSectionTree(vo);
        } else {
            //map.put("IsAuto", 1); //默认自动断面
            list = publicToolsService.RiverSectionTree(vo);
        }
        return AjaxResult.success(list);
    }

    /**
     * 控制类型树监测断面
     */
public AjaxResult controlTypeTree(){
    return null;
}

    /**
     * 手工监测数据最新监测时间
     */
    @GetMapping("/manualMonitordataLastTime")
    public AjaxResult manualMonitordataLastTime(PublicToolsVo vo){
        Map<String,Object> map = publicToolsService.manualMonitordataLastTime(vo);
        return AjaxResult.success(map);
    }

    /**
     * 湖库树形结构
     */
    @GetMapping("/lakeSegmentTree")
    public AjaxResult lakeSegmentTree(PublicToolsVo vo){
        if (StringUtils.isNotEmpty(vo.getControlLevel())) {
            String[] arr = vo.getControlLevel().split(",");
            List<String>  controlLevels = Arrays.asList(arr);
            vo.setControlLevels(controlLevels);
        }

        if (StringUtils.isNotEmpty(vo.getAssessTypeCode())) {
            String[] arr = vo.getAssessTypeCode().split(",");
            List<String>   assessTypeCodes = Arrays.asList(arr);
            vo.setAssessTypeCodes(assessTypeCodes);
        }
        List<Map<String,Object>> list = new ArrayList<>();
        //outCountry传值1的时候，增加where条件判断，and ifnull(IsCountryAuto,0)!=1。默认参数值为0，返回全部数据，不加这个条件
        if ("IsManual".equals(vo.getSegmentType())) {
            list = publicToolsService.lakeSegmentTree(vo);
        } else if ("IsAuto".equals(vo.getSegmentType())) {

            list = publicToolsService.lakeSegmentTree(vo);
        } else {
            //map.put("IsAuto", 1); //默认自动断面
            list = publicToolsService.lakeSegmentTree(vo);
        }
        return AjaxResult.success(list);
    }

    /**
     * 按照区划 湖库断面树
     */
    @GetMapping("/lakeSegmentRegionTree")
    public AjaxResult lakeSegmentRegionTree(PublicToolsVo vo){
        if (StringUtils.isNotEmpty(vo.getControlLevel())) {
            String[] arr = vo.getControlLevel().split(",");
            List<String>  controlLevels = Arrays.asList(arr);
            vo.setControlLevels(controlLevels);
        }

        if (StringUtils.isNotEmpty(vo.getAssessTypeCode())) {
            String[] arr = vo.getAssessTypeCode().split(",");
            List<String>   assessTypeCodes = Arrays.asList(arr);
            vo.setAssessTypeCodes(assessTypeCodes);
        }
        List<Map<String,Object>> list = publicToolsService.lakeSegmentRegionTree(vo);
        return AjaxResult.success(list);
    }

}
